package com.sanhuo.idms.dao;

import com.sanhuo.idms.entity.RepairPersonal;
import com.sanhuo.idms.vo.RepairPageVO;
import com.sanhuo.idms.vo.RepairPersonalVO;
import com.sanhuo.idms.vo.TaskNumVO;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.annotation.Mapper;
import com.sanhuo.triild.annotation.Select;
import com.sanhuo.triild.page.Page;
import com.sanhuo.triild.page.PageSearch;

@Mapper
public interface RepairPersonalMapper extends BaseMapper<RepairPersonal> {
    @Select("select user.id id,user.name name, phone,gender,taskNum,qq,email from repair_personal join user on user.id = repair_personal.id ")
    Page<RepairPersonalVO> list(PageSearch pageSearch);

    @Select("select user.id id,user.name name, phone,gender,taskNum" +
            " from repair_personal join user on user.id = repair_personal.id" +
            "  where user.id = #{userId}")
    RepairPersonalVO detailVO(String userId);

    @Select("select concat(t.num ,\"-\",rm.num) dorm,r.device,r.content,r.state,r.updateTime,r.id ,u.name creator from" +
            " repair r join repair_task rt join user u join dorm d join tung t " +
            " join room rm on r.dormId = d.id   and d.roomId = rm.id and d.tungId = t.id and u.id = r.creatorId and rt.repairId = r.id where" +
            " rt.personalId = #{personId}")
    Page<RepairPageVO> mytask(String personalId, PageSearch pageSearch);

    @Select("select count(rt.id) unFinishNum,rp.taskNum finishNum from repair r join repair_task rt join repair_personal rp" +
            " on r.id = rt.repairId and rt.personalId = rp.id where r.state not like '3' and rp.id= #{id}")
    TaskNumVO countTaskNum(String id);

}
